﻿
using SMARTMobile.ViewModels;
using System.Windows;
namespace SMARTMobile.Views
{
	public partial class MainMvvmPage
	{
		private bool _isSidebarVisible = false;

		public MainMvvmPage()
		{
			InitializeComponent();
		}

		protected override void OnPageLoaded(System.Windows.RoutedEventArgs e)
		{
			MainViewModel viewModel = this.DataContext as MainViewModel;
			if (viewModel == null)
				return;

			viewModel.ShowSidebar += this.SidebarStateChange;
		}

		protected override void OnPageUnloaded(System.Windows.RoutedEventArgs e)
		{
			MainViewModel viewModel = this.DataContext as MainViewModel;
			if (viewModel == null)
				return;

			viewModel.ShowSidebar -= this.SidebarStateChange;
		}

		private void SidebarStateChange(object obj)
		{
			if (this._isSidebarVisible)
			{
				VisualStateManager.GoToState(this, "SidebarClosedState", true);
				this._isSidebarVisible = false;
			}
			else
			{
				VisualStateManager.GoToState(this, "SidebarOpenState", true);
				this._isSidebarVisible = true;
			}
		}
	}
}